package oms.ck.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import oms.ck.util.DBUtil;

public class saydao {
	
	//获取数据总条数
	public int getTotalCount()
	{
		int count = 0;
		try {
			
			Connection conn = DBUtil.getConnection();
			String sql = "select count(*) c from says";
			PreparedStatement prep=conn.prepareStatement(sql);
			ResultSet rs=prep.executeQuery();
			if(rs.next()){
				count=rs.getInt("c");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}
	//查询句子
	public String getSentence(int id) {
		String sentence = null;
		try {
			Connection conn = DBUtil.getConnection();
			String sql = "select sentence from says where id = ?";
			PreparedStatement prep=conn.prepareStatement(sql);
			prep.setInt(1,id);
			ResultSet rs=prep.executeQuery();
			if(rs.next()){
				sentence=rs.getString("sentence");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return sentence;
	}
}
